/*
 * Author: http://www.redwolf-soft.com
 * All Rights Reserved
 * 
 * 2013.11
 *   
 * */
package com.redwolfsoft.libshoppingserver.brand;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;



public class CountryCategory {
	public final static String TAG = "CountryCategory";
	
	public String id = null;
	public String mDisplayName = null;
	public List<BrandInfo> mBrandList= null;
	
	
	public CountryCategory(String id, String name, List<BrandInfo> list)
	{
		this.id=id;
		mDisplayName=name;
		mBrandList=list;
		
	}
	public CountryCategory(JSONObject obj)
	{
		if(obj==null)
		{
			//Log.w(TAG, "JSONObject is null");
			return;
		}
		//try {		
			id = obj.getString("id");
			mDisplayName = obj.getString("mDisplayName");			
			
			mBrandList = new ArrayList<BrandInfo>();
			JSONArray array1 = obj.getJSONArray("mBrandList");
			for(int i=0;i<array1.size();i++)
			{				
				mBrandList.add(new BrandInfo(array1.getJSONObject(i)));
			}
			
			
		/*} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
	}
	
	public JSONObject toJsonObject()
	{
		JSONObject obj = new JSONObject();
		//JSONObject obj2 = new JSONObject();
		//try {
			obj.put("id", id);
			obj.put("mDisplayName", mDisplayName);
			JSONArray array1 = new JSONArray();
			for(int i=0;i<mBrandList.size();i++)
			{
				array1.add(i,mBrandList.get(i).toJsonObject());
			}
			obj.put("mBrandList", array1);
			
			//obj2.put(TAG, obj);
		/*} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}*/
		return obj;
		
	}
}
